<?php
/**
 * Created by PhpStorm.
 * User: lgy
 * Date: 2018/6/30
 * Time: 19:21
 */

namespace app\admin\controller;
use app\admin\model\Admin AS AdminModel;
class Base
{
	protected $admin_sxxcpd_user;
	protected $admin_sxxcpd_level;
	protected $beforeActionList = [
		'islogin' => ['except' => 'login,checkadmin,cogradientData,addClickNumAuto'],
	];

	//检查登录
	public function checkadmin()
	{
		$request = Request::instance();
		$params = $request->param();
		$result = AdminModel::checkAdmin($params);
		if ($result) {
			Session::set('admin_sxxcpd_id', $result['id']);
			Session::set('admin_sxxcpd_user', $result['user']);
			Session::set('admin_sxxcpd_level', $result['level']);
			$this->success('登录成功', 'admin/index/index');
		} else {
			$this->error('用户名或者密码错误');
		}

	}

	protected function islogin()
	{
		$this->admin_sxxcpd_user = Session::get('admin_sxxcpd_user');
		$this->admin_sxxcpd_level = Session::get('admin_sxxcpd_level');
		if (!$this->admin_sxxcpd_user) {
			$this->redirect('admin/login');
			return false;
		}
		if ($this->admin_sxxcpd_level < 128) {
			$this->error('权限不足', 'admin/login');
			return false;
		}
	}

}